package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo8 {
    public static void main(String[] args) throws SQLException {
        Connection connection = DBUtil.getConnection();
        String sql = "INSERT INTO userinfo (username, password, nickname, age) " +
                "VALUES (?, ?, ?, ?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, "张三");
        preparedStatement.setString(2, "123456");
        preparedStatement.setString(3, "阿三");
        preparedStatement.setInt(4, 12);
        int sum = preparedStatement.executeUpdate();
        if (sum > 0) {
            System.out.println("插入成功");
        } else {
            System.out.println("插入失败");
        }
    }
}
